package com.y.architecture.widget;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.y.architecture.R;
import com.zhengsr.viewpagerlib.GlideManager;
import com.zhengsr.viewpagerlib.anim.MzTransformer;
import com.zhengsr.viewpagerlib.bean.PageBean;
import com.zhengsr.viewpagerlib.callback.PageHelperListener;
import com.zhengsr.viewpagerlib.indicator.ZoomIndicator;
import com.zhengsr.viewpagerlib.view.BannerViewPager;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by youjingjing on 2017/11/21.
 */

public class CarouselUtil {

    private Integer[] res = {R.mipmap.guide1,R.mipmap.guide2,R.mipmap.guide3,
            R.mipmap.guide4 };

    private String[] resUrl = {
            "http://img.mukewang.com/54bf7e1f000109c506000338-590-330.jpg",
            "http://upload.techweb.com.cn/2015/0114/1421211858103.jpg",
            "http://img1.cache.netease.com/catchpic/A/A0/A0153E1AEDA115EAE7061A0C7EBB69D2.jpg",
            "http://image.tianjimedia.com/uploadImages/2015/202/27/57RF8ZHG8A4T_5020a2a4697650b89" +
                    "c394237ba9ffbb45fe8555a2cbec-6O6nmI_fw658.jpg"};

    private String[] text = {"图像处理","LSB开发","游戏开发","梦想"};
    private BannerViewPager mBannerCountViewPager;
    List<LoopBean> loopBeens;
    PageBean bean;
    Context context;

    public CarouselUtil(Context context, List<LoopBean> loopBeens, BannerViewPager mBannerCountViewPager, Integer[] res, String[] resUrl, String[] text) {
        this.mBannerCountViewPager = mBannerCountViewPager;
        this.loopBeens = loopBeens;
        this.resUrl = resUrl;
        this.res = res;
        this.text = text;
        this.context = context;
    }
    public CarouselUtil(Context context, List<LoopBean> loopBeens, BannerViewPager mBannerCountViewPager, Integer[] res, String[] resUrl) {
        this.mBannerCountViewPager = mBannerCountViewPager;
        this.loopBeens = loopBeens;
        this.res = res;
        this.resUrl = resUrl;
        this.context = context;
    }

    public void initCarousel(ZoomIndicator zoomIndicator) {
          /*配置数据*/
        List<LoopBean> loopBeens = new ArrayList<>();
        for (int i = 0; i < text.length; i++) {
            LoopBean bean = new LoopBean();
            bean.url = resUrl[i];
            bean.text = text[i];
            loopBeens.add(bean);
        }
    /*配置PageBean*/
       bean = new PageBean.Builder<LoopBean>()
                .setDataObjects(loopBeens)
                .setIndicator(zoomIndicator)
                .builder();
     /*设置viewpager的动画*/
     mBannerCountViewPager.setPageTransformer(false,new MzTransformer());
    }

    public void setPagerListener(){
          /*view 的接口提供出来*/
        mBannerCountViewPager.setPageListener(bean, R.layout.loop_layout, new PageHelperListener() {
            @Override
            public void getItemView(View view, Object data) {
                ImageView imageView = view.findViewById(R.id.loop_icon);
                LoopBean bean = (LoopBean) data;
                new GlideManager.Builder()
                        .setContext(context)
                        .setImgSource(bean.url)
                        .setLoadingBitmap(R.mipmap.ic_launcher)
                        .setImageView(imageView)
                        .builder();
                TextView textView = view.findViewById(R.id.loop_text);
                textView.setText(bean.text);

                //如若你要设置点击事件，也可以直接通过这个view 来设置，或者图片的更新等等
            }
        });
    }

}
